Skip to content

feat(hooks): bridge SessionStart and SessionEnd Claude Code hook events#2394

Open
jainnam-1993 wants to merge 1 commit intocode-yeongyu:devfrom
jainnam-1993:feat/session-start-end-hooks
Open

feat(hooks): bridge SessionStart and SessionEnd Claude Code hook events#2394
jainnam-1993 wants to merge 1 commit intocode-yeongyu:devfrom
jainnam-1993:feat/session-start-end-hooks

Conversation

@jainnam-1993
Copy link

@jainnam-1993 jainnam-1993 commented Mar 8, 2026

Summary

Completes the Claude Code hook compatibility layer from 5/7 to 7/7 hook events by adding SessionStart and SessionEnd bridging.

Problem

oh-my-opencode bridges 5 of 7 Claude Code hook events (PreToolUse, PostToolUse, UserPromptSubmit, Stop, PreCompact), but SessionStart and SessionEnd are missing. This breaks session context injection for users relying on Claude Code hooks — for example, ECC's session-start.js which injects previous session summaries, or custom session-context-loader.sh hooks.

Solution

Bridge the two missing events using the same patterns established by the existing hook bridge:

  • session.created (OpenCode) → SessionStart (Claude Code) — hook stdout is collected and injected into the session context via ctx.client.session.prompt() + createInternalAgentTextPart()
  • session.deleted (OpenCode) → SessionEnd (Claude Code) — fire-and-forget execution

Files Changed

File Change
types.ts Add SessionStart/SessionEnd to ClaudeHookEvent union, ClaudeHooksConfig, plus input interfaces
config.ts Add both events to normalizer and merger eventTypes arrays
config-loader.ts Add both events to mergeDisabledHooks()
session-start.ts (new) executeSessionStartHooks (collects stdout) + executeSessionEndHooks (fire-and-forget)
session-event-handler.ts Wire session.created → SessionStart and session.deleted → SessionEnd

Design Decisions

  • No exit-code-2 blocking for SessionStart (matches Claude Code behavior)
  • SessionEnd is fire-and-forget (no blocking, no injection)
  • Subagent sessions skipped via parentSessionId check (matches Stop hook pattern)
  • isHookDisabled() respected for both new events
  • Zero impact on existing 5 hook event behaviors

Verification

  • bun run typecheck — passes (zero errors)
  • bun run build — succeeds

Summary by cubic

Bridges Claude Code SessionStart and SessionEnd hook events, completing the compatibility layer (5/7 → 7/7). On session create, hook stdout is injected into the session; on session delete, hooks run and per-session state is cleared.

  • New Features
    • Map OpenCode session.createdSessionStart; inject stdout via ctx.client.session.prompt() with createInternalAgentTextPart().
    • Map session.deletedSessionEnd; fire-and-forget execution and clear per-session hook state.
    • Add types/config support and executeSessionStartHooks/executeSessionEndHooks; skip subagent sessions; respect disabled hooks; no exit-code-2 blocking for SessionStart.

Written for commit f4139ce. Summary will update on new commits.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Adds SessionStart/End hooks following established patterns; changes are additive and well-isolated from existing hook logic, ensuring no regressions.


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

@jainnam-1993
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@acamq
Copy link
Collaborator

acamq commented Mar 9, 2026

recheck

@acamq
Copy link
Collaborator

acamq commented Mar 9, 2026

@jainnam-1993 It looks like the email of the commit and your github account do not match. Please re-author the commit with an email that is linked to your GitHub account (your no-reply github email works).

Complete the Claude Code hook compatibility layer from 5/7 to 7/7 events.

Previously, oh-my-opencode bridged PreToolUse, PostToolUse, UserPromptSubmit,
Stop, and PreCompact — but SessionStart and SessionEnd were missing. This broke
session context injection for users relying on Claude Code hooks (e.g., ECC's
session-start.js which injects previous session summaries).

Changes:
- types.ts: Add SessionStart/SessionEnd to ClaudeHookEvent union and
  ClaudeHooksConfig interface, plus SessionStartInput/SessionEndInput types
- config.ts: Add both events to normalizer and merger arrays
- config-loader.ts: Add both events to disabled hooks merger
- session-start.ts (new): executeSessionStartHooks collects stdout from
  matching hooks for context injection; executeSessionEndHooks fires hooks
  on session deletion (fire-and-forget)
- session-event-handler.ts: Wire session.created -> SessionStart (with
  stdout injection via session.prompt) and session.deleted -> SessionEnd

Design decisions:
- SessionStart stdout is injected into session context via
  ctx.client.session.prompt() + createInternalAgentTextPart()
- No exit-code-2 blocking for SessionStart (matches Claude Code behavior)
- SessionEnd is fire-and-forget (no blocking, no injection)
- Subagent sessions are skipped (parentSessionId check)
- isHookDisabled() respected for both new events
@jainnam-1993 jainnam-1993 force-pushed the feat/session-start-end-hooks branch from 69b7e03 to f4139ce Compare March 9, 2026 01:39
@jainnam-1993
Copy link
Author

recheck

github-actions bot added a commit that referenced this pull request Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants